﻿-- Define the relationship between PersonRoleAccess and SecurityRole
ALTER TABLE [dbo].[PersonRoleAccess] WITH CHECK ADD  
       CONSTRAINT [FK_PersonRoleAccess_SecurityRole] FOREIGN KEY([SecurityRole])
REFERENCES [dbo].[SecurityRole] ([RoleId])
ON DELETE NO ACTION
GO
-- Define the relationship between PersonRoleAccess and Person
ALTER TABLE [dbo].[PersonRoleAccess] WITH CHECK ADD  
       CONSTRAINT [FK_PersonRoleAccess_Person] FOREIGN KEY([Person])
REFERENCES [dbo].[Person] ([PersonId])
ON DELETE NO ACTION
GO
-- Define the relationship between PersonRoleAccess and Person
ALTER TABLE [dbo].[PersonRoleAccess] WITH CHECK ADD  
       CONSTRAINT [FK_PersonRoleAccess_CreatedByPerson] FOREIGN KEY([CreatedBy])
REFERENCES [dbo].[Person] ([PersonId])
ON DELETE NO ACTION
GO
-- Define the relationship between PersonRoleAccess and Person
ALTER TABLE [dbo].[PersonRoleAccess] WITH CHECK ADD  
       CONSTRAINT [FK_PersonRoleAccess_LastChangedBy] FOREIGN KEY([LastChangedBy])
REFERENCES [dbo].[Person] ([PersonId])
ON DELETE NO ACTION
GO
-- Define the relationship between PersonRoleAccess and Person
ALTER TABLE [dbo].[PersonRoleAccess] WITH CHECK ADD  
       CONSTRAINT [FK_PersonRoleAccess_PersonAccessing] FOREIGN KEY([PersonAccessing])
REFERENCES [dbo].[Person] ([PersonId])
ON DELETE NO ACTION
GO